/**@file: 路由文件 */
import Vue from 'vue';
import VueRouter from 'vue-router';

Vue.use(VueRouter);

const _import_ = file => () =>
	import('../views/' + file + '.vue');

export const routes = [
	// 首页
	{
		path: '/',
		component: _import_('Home'),
		redirect: '/home',
		meta: {
			title: '首页',
			icon: 'home.png',
			active: 'home_active.png',
			path: '/home',
			level: 1
		},
		children: [{
			path: 'home',
			meta: {
				title: '首页',
				isMenu: true
			},
			component: _import_('Index/Index'),
		}]
	},
	// 获客工具
	{
		path: '/live_code',
		component: _import_('Home'),
		redirect: '/live_code/manage',
		meta: {
			icon: 'code.png',
			active: 'code_active.png',
			title: '获客工具',
			path: '/live_code/manage'
		},
		children: [{
				path: 'manage',
				meta: {
					title: '渠道活码',
					isMenu: true
				},
				component: _import_('LiveCode/CodeManage'),
			},
			{
				path: 'add',
				meta: {
					title: '新建渠道活码',
				},
				component: _import_('LiveCode/AddCode'),
			},
		]
	},
	// 客户CRM
	{
		path: '/custom_crm',
		component: _import_('Home'),
		redirect: '/custom_crm/manage',
		meta: {
			icon: 'custom.png',
			active: 'custom_active.png',
			title: '客户CRM',
			path: '/custom_crm/manage'
		},
		children: [{
				path: 'manage',
				meta: {
					title: '客户',
					isMenu: true
				},
				component: _import_('CustomCrm/CustomManage'),
			},
			{
				path: 'label',
				meta: {
					title: '客户标签',
					isMenu: true
				},
				component: _import_('CustomCrm/CustomLabel'),
			},
			{
				path: 'base',
				meta: {
					title: '客户群',
					isMenu: true
				},
				component: _import_('CustomCrm/CustomBase'),
			},
		]
	},
	// 企业管理
	{
		path: '/address_book',
		component: _import_('Home'),
		redirect: '/address_book/member_list',
		meta: {
			icon: 'book.png',
			active: 'book_active.png',
			title: '企业管理',
			path: '/address_book/member_list'
		},
		children: [{
				path: 'member_list',
				meta: {
					title: '员工管理',
					isMenu: true
				},
				component: _import_('AddressBook/Member'),
			},
			{
				path: 'label_list',
				meta: {
					title: '企业标签',
					isMenu: true
				},
				component: _import_('AddressBook/Label'),
			},
		]
	},
	// 销售工具
	{
		path: '/content',
		component: _import_('Home'),
		redirect: '/content/manage',
		meta: {
			icon: 'chat.png',
			active: 'chat_active.png',
			title: '销售工具',
			path: '/content/manage'
		},
		children: [{
				path: 'manage',
				meta: {
					title: '聊天工具栏',
					isMenu: true,
					keepAlive: true // 需要被缓存
				},
				component: _import_('Content/ContentManage')
			},
			{
				path: 'addgraphic',
				meta: {
					title: '添加图文',
				},
				component: _import_('Content/AddGraphic'),
			},
		]
	},
	// 子账户管理
	{
		path: '/account',
		component: _import_('Home'),
		redirect: '/account/index',
		meta: {
			icon: 'account.png',
			active: 'active_account.png',
			title: '子账户管理',
			path: '/account/index',
			level: 1
		},
		children: [{
			path: 'index',
			meta: {
				title: '子账号管理',
				isMenu: true
			},
			component: () => import('@/views/Account'),
		}]
	},
	{
		path: '/login',
		name: 'Login',
		component: _import_('Login'),
	},
	{
		path: '/install',
		name: 'Install',
		component: _import_('Install/Install'),
	},
]

const router = new VueRouter({
	mode: 'history',
	routes
});
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location, onResolve, onReject) {
	if (onResolve || onReject) {
		return originalPush.call(this, location, onResolve, onReject);
	}
	return originalPush.call(this, location).catch(err => err);
};

export default router;
